home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14465 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character
  5. Date: Sun, 14 Apr 1996 14:28:21 GMT
  6. Organization: Netcom
  7. Message-ID: <317109ea.316698628@nntp.ix.netcom.com>
  8. References: <4kj66f$k0o@ren.cei.net> <1996Apr11.192937.25676@sq.com> <829396473snz@genesis.demon.co.uk> <4kpd2g$eeb@masala.cc.uh.edu>
  9. NNTP-Posting-Host: ix-dc13-11.ix.netcom.com
  10. X-NETCOM-Date: Sun Apr 14  9:30:05 AM CDT 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. cosc19z5@Bayou.UH.EDU (Spasmo) wrote:
  14.  
  15. > Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
  16. > : In article <1996Apr11.192937.25676@sq.com> msb@sq.com "Mark Brader" writes:
  17. > [Snip]
  18. > : >In the specific case of a string obtained from fgets(), we can be
  19. > : >sure that if there is a newline then it is the last character.
  20. > : >This leads to the alternative approach:
  21. > : >
  22. > : >  ptr = strchr (buffer, '\n');   /* or strrchr() */
  23. > : >  if (ptr) *ptr = '\0';
  24. > Ok, I've got a question at this point.  Is it really proper to say
  25. > if (ptr)?  From what I've read, NULL wasn't supposed to be guaranteed
  26. > to work with true/false tests like the above, so the only safe way
  27. > was if (ptr != NULL).  As a matter of fact, that's what Stroustrup
  28. > mentioned in his C++ book as a reason for using 0 instead of the NULL
  29. > pointer when using C++, so that true/false tests could be safely performed.
  30. > If I'm wrong please tell me since I've been sticking with ptr != NULL
  31. > now for the very reason of safety.  I would love to go for a good old
  32. > true/false test rather than a NULL comparison if in fact this is
  33. > valid regardless of implementation.  I've learned to stay away from
  34. > testing code and going with the results since different implementations
  35. > have different behaviors at times so even if my own experience would
  36. > have shown the true/false approach to work I still would have avoided
  37. > it until I heard an official "yes it can be done, or no it can't".
  38.  
  39. Read some different books.
  40.  
  41.     if (ptr)
  42.       statement1
  43.  
  44. executes statement1 if ptr compares equal to 0 (ISO 6.6.4), i.e., if
  45. ptr == 0.
  46.  
  47. 0 is a null pointer constant (ISO 6.2.2.3)
  48.  
  49. Michael M Rubenstein
  50.